﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class EditZhuangControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Panel panel1 = (Panel)FindControl("panel1");
            if (!base.Page.IsPostBack)
            {
                Persistence1.Table = "zs_prozhuang";
                Persistence1.Key = "ID";
                Persistence1.KeyValue = HttpContext.Current.Request["zid"];
                Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();
            }
            Persistence1.BindControl = panel1;
            BindData();
            IsLookPerson();
        }

        private void IsLookPerson()
        {
            string sql = "Select rolename from zs_role where id in (Select roleid from zs_user_in_role where userid = '" + userid + "')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["rolename"].ToString().Equals("查看人员"))
                    {
                        Button btnSave = (Button)FindControl("btnSave");
                        btnSave.Visible = false;
                    }
                }
            }
        }


        protected override void OnPreRender(EventArgs e) {
            base.OnPreRender(e);
            TextBox txtPNID = (TextBox)FindControl("txtPNID");
            if (string.IsNullOrEmpty(txtPNID.Text.Trim())) { txtPNID.Text = HttpContext.Current.Request["PID"]; }
        }
        protected void BindData() {
            Button btnSave = (Button)FindControl("btnSave");
            Button Button1 = (Button)FindControl("Button1");
            btnSave.Click += new EventHandler(btnSave_Click);
            Button1.Click += new EventHandler(BtnCancel_Click);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Persistence1.Update();

            HttpContext.Current.Response.Redirect("ProjectZhuang.aspx?PID=" + HttpContext.Current.Request["PID"] + "&query=" + HttpContext.Current.Request["query"]);
            //HttpContext.Current.Response.Redirect("EditZhuang.aspx?ZID=" + Persistence1.KeyValue + "&PID=" + HttpContext.Current.Request["PID"]);
        }
        protected void BtnCancel_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Redirect("ProjectZhuang.aspx?PID=" + HttpContext.Current.Request["PID"] + "&query=loupan");
        }
    }
}


